package com.itheima.apis.book.fallback;


import com.itheima.apis.book.IBookClient;
import com.itheima.model.book.dtos.BookAdminDto;
import com.itheima.model.book.dtos.BookSaveDto;
import com.itheima.model.common.dtos.ResponseResult;
import com.itheima.model.common.enums.AppHttpCodeEnum;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * IBookClient降级处理
 * 当book-service不可用时，返回默认响应
 */
@Component
public class IBookClientFallBack implements IBookClient {

    @Override
    public ResponseResult getBookVo(Integer bookId) {
        return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR, "图书服务暂时不可用");
    }

    @Override
    public ResponseResult getBooksByCategory(Integer categoryId, Integer page, Integer size) {
        return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR, "图书服务暂时不可用");
    }

    @Override
    public ResponseResult getNewBooks(Integer page, Integer size) {
        return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR, "图书服务暂时不可用");
    }

    // ==================== 管理端接口降级 ====================

    @Override
    public ResponseResult adminListBooks(BookAdminDto dto) {
        return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR, "图书服务暂时不可用，无法查询图书列表");
    }

    @Override
    public ResponseResult adminGetBookById(Integer id) {
        return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR, "图书服务暂时不可用，无法获取图书详情");
    }

    @Override
    public ResponseResult adminAddBook(BookSaveDto dto) {
        return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR, "图书服务暂时不可用，无法新增图书");
    }

    @Override
    public ResponseResult adminUpdateBook(Integer id, BookSaveDto dto) {
        return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR, "图书服务暂时不可用，无法更新图书");
    }

    @Override
    public ResponseResult adminDeleteBook(Integer id) {
        return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR, "图书服务暂时不可用，无法删除图书");
    }

    @Override
    public ResponseResult adminBatchDeleteBooks(List<Integer> ids) {
        return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR, "图书服务暂时不可用，无法批量删除图书");
    }
}
